const mongoose=require("mongoose");
mongoose.connect("mongodb://localhost/test");
mongoose.Promise=Promise;

const Schema=mongoose.Schema({
  name:String,
  age:Number
});

const User=mongoose.model("User",Schema);

                    async function run(){
                      await User.remove();
                    var  u1=await new User({name:"yuqin",age:23});
                    var  u2=await new User({name:"yuqin",age:90909});
                        await u1.save();
                            await u2.save();
                            //调用User.remove()删除指定条件的数据对象
                      await User.remove({age:90909});
                      console.log(await User.find({name:"yuqin"}));
                      //数据对象调用·remove()方法删除从数据库中自己
                      await u1.remove();
                      console.log(await User.findById(u1.id));
                      //利用保存在JS中对象不会被删除的特点，可以拿到数据库中被删除的数据
                      var {name}=u1;
                      var u3=await new User({name:name,age:23});
                      console.log(u3);
                      }

                      run();
